import { UserService } from './../../../../@core/services/user/user.service';
import { Component, Input } from '@angular/core';
import { DialogService } from 'ng-devui';
import { EncodeRulesService } from 'src/app/@core/services/encoderRule/encode-rules.service';
import { SelectUserComponent } from 'src/app/@shared/components/select-user/select-user.component';
@Component({
  selector: 'app-add-position',
  templateUrl: './add-position.component.html',
  styleUrls: ['./add-position.component.scss']
})
export class AddPositionComponent {
  @Input() data: any;
  options: any;//仓库
  user: any;
  name: string;
  config = {
    maxHeight: '400px',
    width: '400px',
    backdropCloseable: true,
  }//弹窗配置
  msgs: Array<Object> = [];
  Position = {
    positionNum: "",
    warehouseId: null,
    positionName: "",
    isEnabled: true,
    userID: null
  };//新增仓库
  items: any[] = [
    '启用', '禁用'
  ];
  currentSelectedItem = '启用';
  constructor(private EncodeRulesService: EncodeRulesService, private dialogService: DialogService, private UserService: UserService) { }
  ngOnInit(): void {
    this.Position.warehouseId = this.data.option.warehouseId
    this.EncodeRulesService.GenerateWarehouseCodeRule('仓位编码','仓位编码').subscribe((res: any) => {
      this.Position.positionNum = res
    })
    this.Position.isEnabled = this.currentSelectedItem == '启用' ? true : false;
    this.UserService.GetAllEmploy(1, 9999).subscribe((res: any) => {
      this.user = res.items
    })
  }
  valueChange(value: string): void {
    this.Position.isEnabled = value == '启用' ? true : false
  }
  positionData(dialogtype?: string) {
    let data = {
      user: this.user,
      display: false,
      placeholder: '请选择人员'
    };
    const results = this.dialogService.open({
      id: 'department',
      ...this.config,
      width: '800px',
      title: '人员',
      data: data,
      content: SelectUserComponent,
      dialogtype: dialogtype,
      onClose: () => {
      },
      buttons: [
        {
          cssClass: 'stress',
          text: '确定',
          handler: ($event: Event) => {
            if (results.modalContentInstance.selectData) {
              this.Position.userID = results.modalContentInstance.selectData.id
              this.name = results.modalContentInstance.selectData.name
              results.modalInstance.hide();
            }
            results.modalInstance.hide();
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }//仓位信息
}
